package com.dong.springboot.web.controller;

import com.dong.springboot.web.autoconfigure.AuthorService;
import com.dong.springboot.web.config.AuthorSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangjian19
 * @date 2018/8/8
 */
@RestController
public class WelcomeController {
    private static final Logger LOGGER = LoggerFactory.getLogger(WelcomeController.class);

    @Value("${author.name}")
    private String name;

    @Value("${author.age}")
    private Integer age;

    @Value("${author.salary}")
    private Double salary;

    @Autowired
    private AuthorSettings authorSettings;

    @Autowired
    private AuthorService authorService;

    @RequestMapping("/")
    public String index() {
        LOGGER.info("===index=== this is index ===>");
        return "Hello Spring Boot!";
    }

    @GetMapping("/author")
    public String author() {
        LOGGER.debug("===author=== author info from properties ===>");
        return "author info. name: + " + name + ", age: " + age + ", salary: " + salary;
    }

    @GetMapping("/author2")
    public String author2() {
        LOGGER.warn("===author2=== author info from authorSettings ===>");
        return "author info. name: + " + authorSettings.getName() + ", age: " + authorSettings.getAge()
                + ", salary: " + authorSettings.getSalary();
    }

    @GetMapping("/author3")
    public String author3() {
        LOGGER.warn("===author3=== author say: auto configure ===>");
        return "author say: " + authorService.sayHello();
    }
}
